class BasicQuery:
    query_type = ""
    question_dsl_examples = {}
    sql_template = ""


class SimpleQuery(BasicQuery):
    query_type = "simple"
    question_dsl_examples = {
        "用户问题：“24年战略地区东进计划北京市KPI收入”。问题的年份为[2024]，月份为None，问题中关键词与数据库字段的映射关系如下：“战略地区”表示{'province': {'in': ['北京', '上海', '广东']}};“东进计划”表示{'city': {'in': ['上海市']}, 'product_lv3': {'in': ['DDD']}}。": {
            "target_field": ["income"],
            "target_name": ["收入"],
            "conditions": {
                "year": {"in": [2024]},
                "province": {"in": ["北京", "上海", "广东"]},
                "city": {"in": ["上海市"]},
                "product_lv3": {"in": ["DDD"]}
            }
        },
        "用户问题：“24年Q2广东DDD收入”。问题的年份为[2024]，月份为[4, 5, 6]，问题中关键词与数据库字段的映射关系如下：“DDD”表示{'product_lv3': {'in': ['DDD']}}。": {
            "target_field": ["income"],
            "target_name": ["收入"],
            "conditions": {
                "year": {"in": [2024]},
                "month": {"in": [4, 5, 6]},
                "province": {"in": ["广东"]},
                "product_lv3": {"in": ["DDD"]}
            }
        },
        "用户问题：“2023年10-12月产互KPI收入情况。”。问题的年份为[2024]，月份为[10, 11, 12]，问题中关键词与数据库字段的映射关系如下：“产互KPI”表示{'product_lv1': {'in': ['产互KPI']}}。": {
            "target_field": ["income"],
            "target_name": ["收入"],
            "conditions": {
                "year": {"in": [2024]},
                "month": {"in": [10, 11, 12]},
                "product_lv1": {"in": ["产互KPI"]}
            }
        }
    }
    sql_template = """
        select {target_field}
        from kpi_data
        where {conditions}
        order by {order_field}
    """


class RankQuery(BasicQuery):
    query_type = "rank"
    question_dsl_examples = {
        "用户问题：“24年战略地区东进计划收入最高的城市”。问题的年份为[2024]，月份为None，问题中关键词与数据库字段的映射关系如下：“战略地区”表示{'province': {'in': ['北京', '上海', '广东']}};“东进计划”表示{'city': {'in': ['上海市']}, 'product_lv3': {'in': ['DDD']}}。": {
            "target_field": ["income"],
            "target_name": ["收入"],
            "group_field": ["city"],
            "group_name": ["城市"],
            "order_dir": "desc",
            "limit": 1,
            "conditions": {
                "year": {"in": [2024]},
                "province": {"in": ["北京", "上海", "广东"]},
                "city": {"in": ["上海市"]},
                "product_lv3": {"in": ["DDD"]}
            }
        },
        "用户问题：“24年Q2广东收入TOP3产品LV3”。问题的年份为[2024]，月份为[4, 5, 6]，问题中关键词与数据库字段的映射关系如下：“广东”表示{'province': {'in': ['广东']}};'product_lv3': {'in': ['DDD']}}。": {
            "target_field": ["income"],
            "target_name": ["收入"],
            "group_field": ["product_lv3"],
            "group_name": ["产品LV3"],
            "order_dir": "desc",
            "limit": 3,
            "conditions": {
                "year": {"in": [2024]},
                "month": {"in": [4, 5, 6]},
                "province": {"in": ["广东"]}
            }
        },
        "用户问题：“2023年10-12月产互KPI收入BOTTOM3省份。”。问题的年份为[2024]，月份为[10, 11, 12]，问题中关键词与数据库字段的映射关系如下：“产互KPI”表示{'product_lv1': {'in': ['产互KPI']}}。": {
            "target_field": ["income"],
            "target_name": ["收入"],
            "group_field": ["province"],
            "group_name": ["省份"],
            "order_dir": "asc",
            "limit": 3,
            "conditions": {
                "year": {"in": [2024]},
                "month": {"in": [10, 11, 12]},
                "product_lv1": {"in": ["产互KPI"]}
            }
        }
    }
    sql_template = """
            select {target_field}
            from kpi_data
            where {conditions}
            group by {group_field}
            order by {order_field}
            limit {limit}
        """


class ComparisonQuery(BasicQuery):
    query_type = "comparison"
    question_dsl_examples = {
        "用户问题：“24年战略地区东进计划收入大于30w的城市”。问题的年份为[2024]，月份为None，问题中关键词与数据库字段的映射关系如下：“战略地区”表示{'province': {'in': ['北京', '上海', '广东']}};“东进计划”表示{'city': {'in': ['上海市']}, 'product_lv3': {'in': ['DDD']}}。": {
            "target_field": ["income"],
            "target_name": ["收入"],
            "group_field": ["city"],
            "group_name": ["城市"],
            "filter_condition": {"income": {"gt": 300000}},
            "conditions": {
                "year": {"in": [2024]},
                "province": {"in": ["北京", "上海", "广东"]},
                "city": {"in": ["上海市"]},
                "product_lv3": {"in": ["DDD"]}
            }
        },
        "用户问题：“24年Q2广东收入大于10000的产品LV3”。问题的年份为[2024]，月份为[4, 5, 6]，问题中关键词与数据库字段的映射关系如下：“广东”表示{'province': {'in': ['广东']}};'product_lv3': {'in': ['DDD']}}。": {
            "target_field": ["income"],
            "target_name": ["收入"],
            "group_field": ["product_lv3"],
            "group_name": ["产品LV3"],
            "filter_condition": {"income": {"gt": 10000}},
            "conditions": {
                "year": {"in": [2024]},
                "month": {"in": [4, 5, 6]},
                "province": {"in": ["广东"]}
            }
        },
        "用户问题：“2023年10-12月产互KPI收入小于1个亿的省份。”。问题的年份为[2024]，月份为[10, 11, 12]，问题中关键词与数据库字段的映射关系如下：“产互KPI”表示{'product_lv1': {'in': ['产互KPI']}}。": {
            "target_field": ["income"],
            "target_name": ["收入"],
            "group_field": ["province"],
            "group_name": ["省份"],
            "filter_condition": {"income": {"lt": 100000000}},
            "conditions": {
                "year": {"in": [2024]},
                "month": {"in": [10, 11, 12]},
                "product_lv1": {"in": ["产互KPI"]}
            }
        }
    }
    sql_template = """
            select {target_field}
            from kpi_data
            where {conditions} and {filter_condition}
            group by {group_field}
        """


query_model_list = [
    SimpleQuery,
    RankQuery,
    ComparisonQuery
]

